package org.example.hadoop.service.wordFrequency;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author wwy
 * @date 2020-11-08 14:26
 */
public class WordFrequencyMapper extends Mapper<LongWritable, Text,Text, IntWritable> {
    private static final IntWritable valueInfo = new IntWritable(1);
    private static Text keyInfo = new Text();
    /**
     * value为一行文本，每个属性用空格分隔,
     * 获取日期
     * @param key
     * @param value
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] valueArray = value.toString().split(" ");
        String key1 = valueArray[8];
        keyInfo.set(key1);
        context.write(keyInfo,valueInfo);
    }
}
